import Taro, { Component } from '@tarojs/taro';
import { View } from '@doctorwork/components';
import { storage } from '@doctorwork/saga';
import { connect } from '@tarojs/redux';
import { parseQuery } from '../../model/utils/common';
import { rewriteAddMTA } from './../../model/utils/rewrite';
@connect(({ web, loading }) => ({
    ...web,
    isLoad: loading.effects['auth/getauthList'],
    isLoadMore: loading.effects['auths/loadMore']
}))
@rewriteAddMTA
export default class Index extends Component {
    constructor(props) {
        super(props);
    }
    config = {
        navigationBarTitleText: '企鹅医生健康商店',
        backgroundTextStyle: 'light',
        navigationBarBackgroundColor: '#fff',
        navigationBarTextStyle: 'black',
        navigationStyle: 'default'
    };
    onShareAppMessage() {
        let { url } = this.$router.params;
        let decodeUrl = decodeURIComponent(url);
        let query = parseQuery(decodeUrl) || '';
        if (decodeUrl.indexOf('quizHome') >= 0) {
            this.props.dispatch({
                type: 'festival/getShareAward',
                payload: {
                    type: 1,
                    extra: {
                        questionnaireId: query.id
                    }
                }
            });
        }
        return {
            title: '全民养生节',
            path: 'pages/index/index'
        };
    }

    componentWillMount() {
        let { url } = this.$router.params;
        let decodeUrl = decodeURIComponent(url);
        // 判断是否跳转到原生小程序
        if (decodeUrl.indexOf('/pages') == 0) {
            wx.redirectTo({
                url: decodeUrl
            });
            return;
        }
        this.props.dispatch({
            type: 'web/setUrl',
            payload: {
                decodeUrl
            }
        });
    }

    render() {
        const { url } = this.props;
        let content = null;
        if (url) {
            setTimeout(() => {
                content = (
                    <web-view src={url} onBindmessage={this.bindmessage} />
                );
            }, 0);
        }

        return <View>{content}</View>;
    }
}
